package com.qfhd.soft.cjzcore.Model;


import com.qfhd.soft.cjzcore.Core.CJJsonUtils;
import com.qfhd.soft.cjzcore.Core.CJLogger;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class Task_image_submit_model {
//     "id": 2,
//     "task_id": 1,
//     "type": 1,
//     "label": "账户邮箱",
//     "place_holder": "您的注册邮箱",
//     "is_delete": 0,
//     "created_at": "2020-04-01 16:38:29",
//     "updated_at": "2020-04-01 16:38:33"
    public int id;
    public int task_id;
    public int type;// 1.字符串  2.图片
//    @SerializedName("label")
    public String title;
//    @SerializedName("place_holder")
    public String tip;
    public int is_delete;
    public String created_at;
    public String updated_at;

    public String exampleImage;

    public String textInput;//字符串类型 输入的字符串
    public String upImageUrl;//图片类型 上传的url

    public static Task_image_submit_model create(int id,int task_id,int type,String title,String tip){
        Task_image_submit_model model = new Task_image_submit_model();
        model.id = id;
        model.task_id = task_id;
        model.type = type;
        model.title = title;
        model.tip = tip;
        return model;
    }

    public static Task_image_submit_model getModelByJSONObject(JSONObject object){
        Task_image_submit_model model = new Task_image_submit_model();
        model.id = CJJsonUtils.getValueFromKey_int(object,"id");
        model.created_at = CJJsonUtils.getValueFromKey_string(object,"created_at");
        model.exampleImage = CJJsonUtils.getValueFromKey_string(object,"exampleImage");
        model.is_delete = CJJsonUtils.getValueFromKey_int(object,"is_delete");
        model.task_id = CJJsonUtils.getValueFromKey_int(object,"task_id");
//        model.textInput = CJJsonUtils.getValueFromKey_string(object,"textInput");
        model.tip = CJJsonUtils.getValueFromKey_string(object,"place_holder");
        model.title = CJJsonUtils.getValueFromKey_string(object,"label");
        model.type = CJJsonUtils.getValueFromKey_int(object,"type");
        model.updated_at = CJJsonUtils.getValueFromKey_string(object,"updated_at");
        return model;
    }

    public static List<Task_image_submit_model> getListByJSONArray(JSONArray array){
        List<Task_image_submit_model> list = new ArrayList<>();
        for(int i=0; i<array.length(); i++){
            try {
                list.add(getModelByJSONObject(array.getJSONObject(i)));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return list;
    }
}
